package code;

import java.util.Arrays;


public class Tupla<E1, E2> {

	private E1 e1;
	private E2 e2;

	public Tupla() {
	}

	public Tupla(E1 e1, E2 e2) {
		this.e1 = e1;
		this.e2 = e2;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Tupla))
			return false;
		
		@SuppressWarnings("unchecked")
		Tupla<E1, E2> other = (Tupla<E1, E2>) obj;
		boolean resul = true;
		//Chequeamos que si los dos son Arrays, hacemos el equals
		if (e1 instanceof Object[] && other.e1 instanceof Object[]){
			Object[] auxE1 = (Object[]) e1;
			Object[] auxOtherE1 = (Object[]) other.e1;
			resul = resul && Arrays.equals(auxE1, auxOtherE1);
		}else{
			resul = resul && e1.equals(other.e1);
		}
		
		resul = resul && e2.equals(other.e2);
		
		return resul;
	}

	public E1 getE1() {
		return e1;
	}

	public void setE1(E1 e1) {
		this.e1 = e1;
	}

	public E2 getE2() {
		return e2;
	}

	public void setE2(E2 e2) {
		this.e2 = e2;
	}

	@Override
	public String toString() {
		StringBuffer ret = new StringBuffer();
		
		if (e1 != null){
			ret.append(System.lineSeparator()).append("Clave: ");
			if(e1 instanceof Object[]){
				Object[] auxE1 = (Object[]) e1;
				for (Object obj : auxE1) {
					ret.append(obj.toString());
				}
			}else{
				ret.append(e1.toString());
			}
		}
		
		
		if (e2 != null){
			ret.append(" Valor: ");
			ret.append(e2.toString());
		}
			

		return ret.toString();
	}

}
